package com.hualan.sfzy.controller.announcementConsult;

import com.hualan.sfzy.entity.announcementConsult.AnnouncementConsult;
import com.hualan.sfzy.service.announcementConsult.AnnouncementConsultService;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class AnnouncementConsultController {
    @Autowired
    private AnnouncementConsultService announcementConsultService;

    @PostMapping("/announcementConsult")
    public Result add(@RequestBody AnnouncementConsult announcementConsult){
        int num = announcementConsultService.add(announcementConsult);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/announcementConsult/{id}")
    public Result remove(@PathVariable Integer id){
        int num = announcementConsultService.remove(id);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/announcementConsult")
    public Result removeBatch(Integer[] ids){
        int num = announcementConsultService.removeBatch(ids);
        return num > 0 ? Result.success() : Result.error();
    }

    @PutMapping("/announcementConsult")
    public Result edit(@RequestBody AnnouncementConsult announcementConsult){
        int num = announcementConsultService.edit(announcementConsult);
        return num > 0 ? Result.success() : Result.error();
    }

    @GetMapping("/announcementConsult/{id}")
    public Result findById(@PathVariable Integer id){
        AnnouncementConsult announcementConsult = announcementConsultService.findById(id);
        return Result.success(announcementConsult);
    }

    @GetMapping("/announcementConsult/page")
    public Result findByPage(@RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNum,
                                         @RequestParam(value = "pageSize",required = false,defaultValue = "2")Integer pageSize,
                                         AnnouncementConsult announcementConsult){
        Map<String, Object> map = announcementConsultService.findByPage(pageNum, pageSize, announcementConsult);
        return Result.success(map);
    }

    @GetMapping("/announcementConsult")
    public Result find(){
        List<AnnouncementConsult> list = announcementConsultService.find();
        return Result.success(list);
    }

}
